/** ***********************************************
 * CodeGen
 *
 * @author  Jonnie Spratley
 * @date 3/05/2009
 * @licence MCIYC
 * @website http://jonniespratley.com/code
 * @contact jonniespratley@gmail.com
 *********************************************** */
package com.jonniespratley.codegen.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.jonniespratley.codegen.business.CodeGenDelegate;
	import com.jonniespratley.codegen.events.CallMethodEvent;
	import com.jonniespratley.codegen.model.ModelLocator;
	import com.jonniespratley.codegen.vo.*;

	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.utils.ArrayUtil;

	/**
	 * For every feature or use case in your application, a corresponding custom command
	 * and event must be created. Each command contains an execute() method that is run
	 * by the framework when the user action has been executed.
	 * These classes are occasionally referred to as worker classes because they carry
	 * out the work for an application.
	 *
	 */
	public class CallMethodCommand implements ICommand, IResponder
	{
		private var model:ModelLocator = ModelLocator.getInstance();

		public function execute( event:CairngormEvent ) : void
		{
			var evt:CallMethodEvent = event as CallMethodEvent;
			var delegate:CodeGenDelegate = new CodeGenDelegate( this );


		}

		public function result( data:Object ) : void
		{
			var result:ResultEvent = data as ResultEvent;
			model.methodCollection = new ArrayCollection( ArrayUtil.toArray( result.result ) );

		}

		public function fault( fault:Object ):void
		{
			var faultEvt:FaultEvent = fault as FaultEvent;
 
			trace(faultEvt.fault.faultString);
		}

	}
}
